package com.raul.prueba.biblioteca.servlets;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.raul.prueba.biblioteca.servlets.vo.VOReserva;
/**
 * Servlet implementation class ReservaServlet
 */
public class ReservaServlet extends HttpServlet {
       
    /**
	 * 
	 */
	private static final long serialVersionUID = 8256257959148828211L;

	/**
     * @see HttpServlet#HttpServlet()
     */
    public ReservaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String accion = request.getParameter("accion");
        List<VOReserva> listaR = (List<VOReserva>) request.getSession().getAttribute("listaReserva");
        VOReserva re = new VOReserva();
        re.setId(Integer.parseInt(request.getParameter("id")));
        re.setISBN(request.getParameter("isbn"));
        re.setTitulo(request.getParameter("titulo"));
        re.setRealizarReserva(request.getParameter("reservar"));
        if (accion.equals("reserva")) {
                for (VOReserva obj: listaR) {
                        if (obj.getISBN().equals(re.ejemplar)) {
                                obj.setRealizarReserva(re.getRealizarReserva());
                                break;
                        }
                }
        }
        response.sendRedirect("reserva.jsp");
        }

}